package cn.flashk.controls.support {
	import com.skins.ImgSkinLoader;
	import com.skins.Skin;
	
	import flash.display.Shape;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;
	
	import cn.flashk.controls.Button;
	import cn.flashk.controls.TabNav;
	import cn.flashk.controls.managers.SkinLoader;
	import cn.flashk.controls.managers.SkinManager;
	import cn.flashk.controls.managers.SourceSkinLinkDefine;
	import cn.flashk.controls.modeStyles.ButtonStyle;
	import cn.flashk.controls.skin.sourceSkin.ButtonSourceSkin;
	
	/**
	 * ...
	 * @author flashk
	 */
	public class Nav extends UIComponent {
		public var isAble:Boolean = true;
		public var index:uint;
		private var closeBtn:Button;
		public var btn:Button;
		private var sh:Shape;
		
		public function Nav(skinID:String=""){
			super(skinID);
			if(_skinID!=""){
				_compoHeight = (Skin.librarys.getSkin(Skin.librarys.sheet.getStyleValue(_skinID,"left"),"up") as ImgSkinLoader).height;
				TabNav.tabHeight = _compoHeight;
			}
			btn = new Button();
			btn.setStyle(ButtonStyle.DEFAULT_SKIN_ELLIPSE_BOTTOM_WIDTH, 0);  //as皮肤
			btn.setStyle(ButtonStyle.DEFAULT_SKIN_ELLIPSE_BOTTOM_HEIGHT, 0);
			this.addChild(btn);
			initSelShow();
		}
		
		public function getTabSkin(tabsNum:uint,tabWidth:Number):void{
			if(_skinID!=""){
				var img:ImgSkinLoader = Skin.librarys.getSkin(Skin.librarys.sheet.getStyleValue(_skinID,"left"),"up") as ImgSkinLoader;
				btn.txtForamt = Skin.librarys.getTextFormat(_skinID,"upTxt");
				if (index == 0){
					btn.setLoaderSkin(Skin.librarys.sheet.getStyleValue(_skinID,"left"))
				} else if (index == tabsNum - 1){
					btn.setLoaderSkin(Skin.librarys.sheet.getStyleValue(_skinID,"right"));
				} else{
					btn.setLoaderSkin(Skin.librarys.sheet.getStyleValue(_skinID,"center"));
				}
				btn.setSize(tabWidth,img.height);
				return;
			}
			
			if (SkinManager.isUseDefaultSkin == false){
				if (index == 0){
					btn.setSkin(SkinLoader.getClassFromSkinFile(SourceSkinLinkDefine.NAV_LEFT));
				} else if (index == tabsNum - 1){
					btn.setSkin(SkinLoader.getClassFromSkinFile(SourceSkinLinkDefine.NAV_RIGHT));
				}else{
					btn.setSkin(SkinLoader.getClassFromSkinFile(SourceSkinLinkDefine.NAV_CENTER));
				}
			}
		}
		
		
		public function set label(value:String):void {
			btn.label = value;
		}
		
		public function get label():String {
			return btn.label;
		}
		
		public function set icon(value:Object):void{
			btn.icon = value;
		}
		
		/**
		 * 设置选中状态 
		 */	
		public function setSelectOn():void {
			isAble = false;
			btn.mouseEnabled = false;
			btn.mouseChildren = false;

			if (SkinManager.isUseDefaultSkin == false){
				btn.removeEventListener(MouseEvent.MOUSE_OUT, ButtonSourceSkin(btn.skinControler).showOut);
				ButtonSourceSkin(btn.skinControler).showPressState();
			} else {
				btn.transform.colorTransform = new ColorTransform(1, 1, 1, 1, 30, 30, 30, 0);
			}
			
		}
		
		public function setSelectOff():void {
			isAble = true;
			btn.mouseEnabled = true;
			btn.mouseChildren = true;
			btn.transform.colorTransform = new ColorTransform();
			if (SkinManager.isUseDefaultSkin == false){
				btn.addEventListener(MouseEvent.MOUSE_OUT, ButtonSourceSkin(btn.skinControler).showOut);
				ButtonSourceSkin(btn.skinControler).showOutState();
			}
		}
		
		override public function setSize(newWidth:Number, newHeight:Number):void {
			super.setSize(newWidth, newHeight);
			btn.setSize(newWidth, newHeight);
		}
		
		override public function updateSkin():void {
			if (sh != null){
				/*sh.graphics.clear();
				sh.graphics.lineStyle(1.5, SkinThemeColor.border, 1);
				var a:Number = 4;
				sh.graphics.moveTo(-3 + a, -3 + a + 1);
				sh.graphics.lineTo(3 + a, 3 + a + 1);
				sh.graphics.moveTo(3 + a, -3 + a + 1);
				sh.graphics.lineTo(-3 + a, 3 + a + 1);*/
			}
		}
		
		protected function initSelShow():void {
		}

	}
}